﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using Common.Utilities.Dispatcher;
using Workflows.Components.Entities.Properties;

namespace Workflows.Components.Entities.MasterData
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    public class FieldInteractionComponent:WorkflowComponentBase
    {
        public FieldInteractionComponent():base()
        {
            this.ComponentActivityType = WorkflowActivityType.SimpleActivity;
            this.ComponentCategory = WorkflowComponentCategory.Entity_Relations.ToString();
            this.Description = "Field dependency to get correspondence, correlation and association scores";
            this.ComponentIcon = Resources.msdtc_IDI_MSDTC_APP_ICON;
            this.ComponentImage = Resources.Node48;
            this.ComponentName = "Field Interactions";

            this._Instruction = new FieldInteractionInstruction(this.ComponentID,Guid.Empty,
                string.Empty,string.Empty,string.Empty,string.Empty,
                string.Empty, new List<string>(), string.Empty);
            this._Output = new FieldInteractionOutput(this.ComponentID, Guid.Empty, string.Empty);
        }

        #region Overrides of WorkflowComponentBase

        private FieldInteractionInstruction _Instruction;
        /// <summary>an object that encapsulate instruction settings.</summary>
        public override InstructionBase Instruction
        {
            get { return _Instruction; }
            set { _Instruction = (FieldInteractionInstruction)value; }
        }

        private FieldInteractionOutput _Output;
        /// <summary>an object to encapsulate output</summary>
        public override ResultBase Output
        {
            get { return _Output; }
            set { _Output = (FieldInteractionOutput)value; }
        }

        #endregion

        public override XmlNode Serialize(ref XmlDocument xDoc, ref XmlNode parentNode)
        {
            XmlNode xNode = base.Serialize(ref xDoc, ref parentNode);
            this.Instruction.Serialize(ref xDoc, ref xNode);
            return xNode;
        }

        public override WorkflowComponentBase Instantiate(XmlNode xNode)
        {
            FieldInteractionComponent component = (FieldInteractionComponent)base.Instantiate(xNode);
            component.Instruction = component.Instruction.Instantiate(xNode.SelectSingleNode("Instruction"));
            return component;
        }
    }
}
